package com.xm;

/**
 * @Author：xm
 * @Project：runoob
 * @Date：2024/7/22 1:14
 */

public class Thread10 extends Thread{
    private String threadName;
    private Thread t;

    public Thread10(String name){
        threadName = name;
        System.out.println("Creating " + threadName);
    }

    @Override
    public void run() {
        System.out.println("Running " + threadName);
        try {
            for (int i = 4; i > 0; i--) {
                System.out.println("Thread：" + threadName + "，" + i);
                // 线程睡眠
                Thread.sleep(50);
            }
        } catch (InterruptedException e) {
            System.out.println("Thread " + threadName + " interrupted");
        }
        System.out.println("Thread " + threadName + " exit");
    }

    public void start() {
        System.out.println("Starting " + threadName);
        if (t == null) {
            t = new Thread(this, threadName);
            System.out.println("t = " + t);
            System.out.println("t.getName() = " + t.getName());
            t.start();
        }
    }

    public static void main(String[] args) {
        Thread10 T1 = new Thread10("Thread-1");
        T1.start();

        Thread10 T2 = new Thread10("Thread-2");
        T2.start();
    }
}
